<template>
    <div class="page-container">
        <Header></Header>

        <div class="main-container">
            <div class="content-grid">
                <!-- 左边栏 -->
                <div class="main-content">
                    <div class="category-card">
                        <h2 class="card-title">
                            分类 ({{ categories.length }})
                        </h2>
                        <div class="category-list">
                            <a v-for="(item, index) in categories" 
                               :key="index"
                               @click="goCategoryArticleListPage(item.categoryId, item.name)" 
                               class="category-item">
                                {{ item.name }}
                                <span class="category-count">{{ item.articlesTotal }}</span>
                            </a>
                        </div>
                    </div>
                </div>
                <!-- 右边栏 -->
                <aside class="sidebar-container">
                  <TagCard />
                </aside>
            </div>
        </div>
        <Footer />
    </div>
</template>

<script setup>
import Header from '@/layouts/components/Header.vue'
import Footer from '@/layouts/components/Footer.vue'
import { useRouter } from 'vue-router'
import { getCategories } from '@/api/frontend/category'
import { ref } from 'vue'
import TagCard from '../../components/TagCard.vue'

const router = useRouter()
const categories = ref([])

const goCategoryArticleListPage = (id, name) => {
    router.push({path: `/category/list/${id}/${name}`})
}

getCategories().then((e) => {
    if (e.success) {
        categories.value = e.data
    }
})
</script>

<style scoped>
.page-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main-container {
  flex: 1;
  max-width: 1230px;
  margin: 0 auto;
  padding: 1.25rem;
  width: 100%;
  box-sizing: border-box;
}

.content-grid {
    display: grid;
    grid-template-columns: 3fr 1fr;
    gap: 1.5rem;
    width: 100%;
}

.category-card {
    background: #fff;
    padding: 1.5rem;
}

.card-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 1.5rem;
}

.category-icon {
    color: #6b7280;
    width: 1.25rem;
    height: 1.25rem;
}

.category-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.category-item {
    display: inline-flex;
    align-items: center;
    padding: 0.375rem 1rem;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 2rem;
    color: #495057;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.category-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 0.5rem;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.375rem;
    border-radius: 1rem;
    background: #e7f5ff;
    color: #339af0;
    font-size: 0.75rem;
}

.category-item:hover {
    background: #f1f3f5;
    border-color: #dee2e6;
}

/* 深色模式 */
@media (prefers-color-scheme: dark) {
    .category-card {
        background: #1f2937;
    }

    .card-title {
        color: #f9fafb;
    }

    .category-icon {
        color: #9ca3af;
    }

    .category-item {
        background: #374151;
        border-color: #4b5563;
        color: #e5e7eb;
    }

    .category-count {
        background: #1f2937;
        color: #60a5fa;
    }

    .category-item:hover {
        background: #4b5563;
        border-color: #6b7280;
    }
}

/* 响应式布局 */
@media (max-width: 768px) {
    .content-grid {
        grid-template-columns: 1fr;
    }

    .main-content,
    .sidebar {
        padding: 0;
    }
}

.sidebar-container {
  min-width: 0;
}
</style>